<?php
namespace model;

/**
 * Description of TblOrder
 *
 * @author Damian
 */
class TblOrder extends Model{
    /**
     * @column
     * @type int
     * @length 11
     * @primary
     * @readwrite
     */
    public $OrderID;
    const ID="OrderID";
    /**
     * @readwrite
     */
    public $CustomerID;
    const CUSTOMER_ID="CustomerID";
    /**
     * @readwrite
     */
    public $OrderDate;
    const ORDER_DATE="OrderDate";
    /**
     * @readwrite
     */
    public $Status;
    const STATUS="Status";
    /**
     * @readwrite
     */
    public $DeliveryMethodID;
    const DELIVERY_METHOD_ID="DeliveryMethodID";
    /**
     * @readwrite
     */
    public $PaymentID;
    const PAYMENT_ID="PaymentID";
    /**
     * @readwrite
     */
    public $ShopID;
    const SHOP_ID="ShopID";
    /**
     * @readwrite
     */
    public $TotalCost;
    const TOTAL_COST="TotalCost";
    
    
     /**
     * @readwrite
     */
    public $AdressID;
    const ADRESS_ID="AdressID";
    
    public static function findIDsByProductID($id){
        $criteria = new Criteria();
//        $criteria->from(TblProductOrder::getModel()->getTable())
//                ->where(TblProductOrder::PRODUCT_ID, "=", $id)->all();
        $all= $criteria->from(TblProductOrder::getModel()->getTable())
                ->where(TblProductOrder::PRODUCT_ID, "=", $id)->all();

        $result = array();
        foreach ($all as $order){
            $result[]=$order["tblproductorder"]["OrderID"];
        }
        return $result;
    }
    public static function createOrderString($id){
//            <select id="order">
//        <option value="1" {if $order==1} selected {/if}>Daty zamówienia rosnąco</option>
//        <option value="2" {if $order==2} selected {/if}>Daty zamówienia malejąco</option>
//        <option value="3" {if $order==3} selected {/if}>Kwocie do zapłaty rosnąco</option>
//        <option value="4" {if $order==4} selected {/if}>Kwocie do zapłaty malejąco</option>
//        <option value="5" {if $order==5} selected {/if}>Nazwisku klienta rosnąco</option>
//        <option value="6" {if $order==6} selected {/if}>Nazwisku klienta malejąco</option>
//    </select>  
        switch ($id){
            case 1: return [TblOrder::ORDER_DATE,"asc",  TblOrder::getModel()->getTable()];
            case 2: return [TblOrder::ORDER_DATE,"desc",  TblOrder::getModel()->getTable()];
            case 3: return [TblOrder::TOTAL_COST,"asc",  TblOrder::getModel()->getTable()];
            case 4: return [TblOrder::TOTAL_COST,"desc",  TblOrder::getModel()->getTable()];
            case 5: return [TblPerson::SURNAME,"asc",  TblPerson::getModel()->getTable()];
            case 6: return [TblPerson::SURNAME,"desc",  TblPerson::getModel()->getTable()];
            default :return [TblOrder::ORDER_DATE,"asc",  TblOrder::getModel()->getTable()];
        }
    }
    
}
